package com.ruoyi.hatha.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hatha.domain.PYue;
import com.ruoyi.hatha.service.IPYueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 钱包余额Controller
 * 
 * @author ruoyi
 * @date 2024-04-03
 */
@RestController
@RequestMapping("/hatha/yue")
public class PYueController extends BaseController
{
    @Autowired
    private IPYueService pYueService;

    /**
     * 查询钱包余额列表
     */
    @PreAuthorize("@ss.hasPermi('hatha:yue:list')")
    @GetMapping("/list")
    public TableDataInfo list(PYue pYue)
    {
        startPage();
        List<PYue> list = pYueService.selectPYueList(pYue);
        return getDataTable(list);
    }


    @GetMapping("/chongzhi")
    public AjaxResult chongzhi(PYue pYue)
    {
        pYue.setCreateUser(SecurityUtils.getUserId());
        pYue.setCreateTime(new Date());
        pYue.setType(1);//充值
        pYueService.insertPYue(pYue);
        return AjaxResult.success();
    }


    @GetMapping("/getjilu")
    public AjaxResult getjilu(PYue pYue)
    {
        pYue.setCreateUser(SecurityUtils.getUserId());
        pYue.setType(1);//充值

        return AjaxResult.success(pYueService.selectPYueList(pYue));
    }
    @GetMapping("/getzhanghu")
    public AjaxResult getzhanghu()
    {
        PYue pYue = new PYue();
        pYue.setUid(SecurityUtils.getUserId());
        PYue np = pYueService.getCount(pYue);
        return AjaxResult.success(np.getNum());
    }

    /**
     * 导出钱包余额列表
     */
    @PreAuthorize("@ss.hasPermi('hatha:yue:export')")
    @Log(title = "钱包余额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PYue pYue)
    {
        List<PYue> list = pYueService.selectPYueList(pYue);
        ExcelUtil<PYue> util = new ExcelUtil<PYue>(PYue.class);
        util.exportExcel(response, list, "钱包余额数据");
    }

    /**
     * 获取钱包余额详细信息
     */
    @PreAuthorize("@ss.hasPermi('hatha:yue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pYueService.selectPYueById(id));
    }

    /**
     * 新增钱包余额
     */
    @PreAuthorize("@ss.hasPermi('hatha:yue:add')")
    @Log(title = "钱包余额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PYue pYue)
    {
        return toAjax(pYueService.insertPYue(pYue));
    }

    /**
     * 修改钱包余额
     */
    @PreAuthorize("@ss.hasPermi('hatha:yue:edit')")
    @Log(title = "钱包余额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PYue pYue)
    {
        return toAjax(pYueService.updatePYue(pYue));
    }

    /**
     * 删除钱包余额
     */
    @PreAuthorize("@ss.hasPermi('hatha:yue:remove')")
    @Log(title = "钱包余额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pYueService.deletePYueByIds(ids));
    }
}
